﻿using MediatR;
using MyMES.Domain.zyy;
using MyMES.Error;
using MyMES.Infrastructure.Interface;
using MyMES.Read.API.Application.Command.Roles;


namespace MyMES.Read.API.Application.Handler.Roles
{
    public class GetRoleHandler : IRequestHandler<GetRolecommand, APIResult<List<Role>>>
    {
        private readonly IBaseRepository<Role> roel;

        public GetRoleHandler(IBaseRepository<Role> roel)
        {
            this.roel = roel;
        }

        /// <summary>
        /// 角色显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<APIResult<List<Role>>> Handle(GetRolecommand request, CancellationToken cancellationToken)
        {
            try
            {
                APIResult<List<Role>> result = new APIResult<List<Role>>();
                result.Code = APIEnum.查询成功;
                result.Msg = "成功";
                string sql = "select *  from Role";
                var list = await roel.SelectAsync(sql);
                result.data = list;
                return result;
            }
            catch (Exception)
            {

                throw;
            }
           
        }
    }
}
